unit uSelect;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue, dxSkinBlueprint,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide,
  dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle, dxSkinFoggy,
  dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian,
  dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus, dxSkinSilver,
  dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008, dxSkinTheAsphaltWorld,
  dxSkinsDefaultPainters, dxSkinValentine, dxSkinVS2010, dxSkinWhiteprint,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, cxPCdxBarPopupMenu, cxContainer,
  cxEdit, cxGroupBox, cxPC, Vcl.Menus, Vcl.StdCtrls, cxButtons, Vcl.ActnList,
  cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage, cxNavigator, Data.DB,
  cxDBData, cxGridLevel, cxClasses, cxGridCustomView, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGrid, Datasnap.DBClient, ClientRowSet,
  cxTextEdit;

type
  TFrmSelect = class(TForm)
    pgSelect: TcxPageControl;
    cxGroupBox1: TcxGroupBox;
    cxTabSheet1: TcxTabSheet;
    ActionList: TActionList;
    actNew: TAction;
    actEdit: TAction;
    actSave: TAction;
    actCancel: TAction;
    actDelete: TAction;
    actRefresh: TAction;
    cxButton13: TcxButton;
    cxButton14: TcxButton;
    tvCust: TcxGridDBTableView;
    GrdcustLevel1: TcxGridLevel;
    Grdcust: TcxGrid;
    crsCust: TClientRowSet;
    dsCust: TDataSource;
    crsCustCLIENT_NO: TStringField;
    crsCustCLIENT_NAME: TStringField;
    crsCustRECIPIENTS: TStringField;
    crsCustMOBILE: TStringField;
    crsCustPROVINCE: TStringField;
    crsCustCITY: TStringField;
    crsCustDISTRICT: TStringField;
    crsCustADDRESS: TStringField;
    tvCustCLIENT_NO: TcxGridDBColumn;
    tvCustCLIENT_NAME: TcxGridDBColumn;
    tvCustRECIPIENTS: TcxGridDBColumn;
    tvCustMOBILE: TcxGridDBColumn;
    tvCustPROVINCE: TcxGridDBColumn;
    tvCustCITY: TcxGridDBColumn;
    tvCustDISTRICT: TcxGridDBColumn;
    tvCustADDRESS: TcxGridDBColumn;
    crsCustID: TStringField;
    procedure actSaveExecute(Sender: TObject);
    procedure actCancelExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    procedure SearchData(aType: Integer);
  public
    { Public declarations }
  end;

var
  FrmSelect: TFrmSelect;
  function SelectData(aType: Integer): string;

implementation
uses uDm, Console, ucommFunction;
{$R *.dfm}

procedure TFrmSelect.actCancelExecute(Sender: TObject);
begin
  Close;
end;

procedure TFrmSelect.actSaveExecute(Sender: TObject);
begin
  if (crsCust.Active) and (crsCust.RecordCount > 0) then
    ModalResult := mrOk;
end;

procedure TFrmSelect.FormCreate(Sender: TObject);
begin
  pSetCaption(Self);
end;

procedure TFrmSelect.SearchData(aType: Integer);
var
  SQLText: string;
begin
  try
    crsCust.DisableControls;
    case aType of
      0 :
        begin
          SQLText := 'SELECT * FROM bas_company_cust WHERE sys_account=' + QuotedStr(userInfo.sysAccount) + ' AND company_id=' + QuotedStr(userInfo.compId);
          OpenDataSet(SQLText, crsCust);
          crsCust.First;
        end;
    end;
  finally
    crsCust.EnableControls;
  end;
end;

function SelectData(aType: Integer): string;
begin
  Result := '';
  Application.CreateForm(TFrmSelect, FrmSelect);
  with FrmSelect do
  try
    pgSelect.ActivePageIndex := aType;
    SearchData(aType);
    if ShowModal = mrOk then
    begin
      case aType of
        0 : Result := crsCust.FieldByName('id').AsString;
      end;
    end;
  finally
    FreeAndNil(FrmSelect);
  end;
end;

end.
